#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#include "dominion.h"

/*
Erik Lawing CS362 Software Engineering II Assignment 4

Points possible: 20

(60 points) Write a random testers for two Dominion cards, one of which has to be the adventurer card. Check these random testers in as randomtestcard.c and randomtestadventurer.c.
(20 points) Add rules to and check in the Makefile to produce randomtestcard.out and randomtestadventurer.out.
(20 points) Write up and check in the development of your random testers, including improvements in coverage and effort to check the correctness of your specification, as randomhistory.txt. Be detailed and thorough!

*/

const int RANDOM_SEED=123456;

int inputRandomPlayerNum()
{
    // TODO: rewrite this function
	int num=1;

	//keep randomizing until a number between 2-MAX_PLAYERS is generated
	while(num<=1){
		num=rand() % MAX_PLAYERS;
	}
	return num;

}

int inputRandomPlayerHand()
{
    // TODO: rewrite this function
	int num=1;

	//keep randomizing until a number between 2-MAX_HAND is generated
	while(num<=1){
		num=rand() % MAX_HAND;
	}
	return num;

}

void testadventurer()
{

	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, sea_hag, tribute, smithy};
	int tcCount=0;

	while(1)
	{

		tcCount++;
		struct gameState state;
		int drawntreasure;
		int currentPlayer=0;
		int cardDrawn=0;
		int temphand[MAX_HAND];
		int z=0;
		int originalcurrentPlayer=0;

		drawntreasure=0;

		currentPlayer=inputRandomPlayerNum();
		state.hand[currentPlayer][inputRandomPlayerHand()]=inputRandomPlayerHand();
		state.handCount[currentPlayer]=inputRandomPlayerNum();
		originalcurrentPlayer=currentPlayer; //for testing later

		//set up the game state with a random number of players
		initializeGame(inputRandomPlayerNum(), k, RANDOM_SEED, &state);

		zzzadventurercardplay(&drawntreasure,state.whoseTurn, cardDrawn, temphand, z, &state);

		printf("Iteration %d: numplayers: %d, currentPlayer = %d, originalcurrentPlayer = %d, drawntreasure = %d, cardDrawn = %d\n", tcCount, state.numPlayers,currentPlayer,originalcurrentPlayer, drawntreasure, cardDrawn);

		if(currentPlayer!=originalcurrentPlayer)
		{
			  printf("error ");
			  exit(200);
		}

	}

}


int main(int argc, char *argv[])
{
    srand(time(RANDOM_SEED));
    testadventurer();
    return 0;
}

/*
 randomtestadventurer >> randomtestadventurer.out
	gcov randomtestadventurer.c >> randomtestadventurer.out

	echo "Result for running random card tests:" > randomtestcard.out
	echo "randomtestcard.c:" >> randomtestcard.out
	gcc -o randomtestcard dominion.c randomtestcard.c rngs.c $(CFLAGS)
	randomtestcard >> randomtestcard.out
	gcov dominion.c >> randomtestcard.out

	*/
